package com.erp.util;

import org.apache.shiro.crypto.hash.Md5Hash;

import java.util.Random;

/**
 * @author pengyujin
 * @date 2020/11/7 0:18
 */
public class SaltUtils {

    /**
     *  * 生成盐的静态方法
     * @param n
     * @return
     */
    public static String getSalt(int n) {
        
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()".toCharArray();

        StringBuilder salt = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char c = chars[new Random().nextInt(chars.length)];
            salt.append(c);
        }
        
        return salt.toString();
    }
    
    public static String shiroMd5(String password, String salt) {
        Md5Hash md5Hash = new Md5Hash(password, salt,1024);
        System.out.println("123");
        System.out.println("1223");
        return md5Hash.toHex();
    }
    
}
